package com.gooddare.view 
{
	import com.gooddare.controller.ApplicationFacade;
	import com.gooddare.locator.ApiLocator;
	import com.gooddare.model.ModelLocator;
	import com.gooddare.model.vo.RuleVO;
	import com.gooddare.view.component.RuleGroupComponent;
	import com.riatimes.mvc.model.vo.DataParamVO;
	import com.riatimes.net.http.HttpService;
	import flash.display.Sprite;
	import org.puremvc.as3.interfaces.INotification;
	/**
	 * ...
	 * @author Lyleff
	 */
	public class PhotopageFrameMediator extends BaseView
	{
		public static var NAME:String = "PhotopageFrameMediator";
		private var photopageFrame:Sprite;
		
		
		private var vo:RuleVO;
		
		public function PhotopageFrameMediator(name:String=null,viewComponent:Object=null) 
		{
			if (name != null) NAME = name;
			if (viewComponent == null) viewComponent = new Sprite();
			super(NAME, viewComponent);
			photopageFrame = getView();
			
			ModelLocator.ROOT.addChild(photopageFrame);
			facade.registerMediator(new DispicFrameMediator());
			
			var ppVO:DataParamVO = new DataParamVO(ApiLocator.API_PHOTOPAGE_JSON_URL, ApplicationFacade.EVENT_APP_PHOTOPAGE_GET_INFO);
			HttpService.getInstance().getData(ApplicationFacade.getInstance(), ppVO);
		}
		override public function listNotificationInterests():Array {
			return[
				ApplicationFacade.EVENT_APP_PHOTOPAGE_GET_INFO,
				ApplicationFacade.EVENT_APP_QUITSTAGE_CLICK,
			]
		}
		override public function handleNotification(note:INotification):void {
			var data:Object = note.getBody();
			switch(note.getName()) {
				case ApplicationFacade.EVENT_APP_PHOTOPAGE_GET_INFO:
					var vo:RuleVO = new RuleVO(data);
					this.vo = vo;
					
					initUI();
					break;
				case ApplicationFacade.EVENT_APP_QUITSTAGE_CLICK:
					clearFrame();
					break;
			}
		}
		
		private function initUI():void 
		{
			createRuleGroup();
		}
		
		private function createRuleGroup():void 
		{
			var rgc:RuleGroupComponent = new RuleGroupComponent(0, vo);
			rgc.x = 130;
			photopageFrame.addChild(rgc);
		}
		
		
		private function clearFrame():void 
		{
			ModelLocator.ROOT.removeChild(photopageFrame);
			facade.removeMediator(NAME);
		}
	}

}